package NG::Gen::Users::Fame;
use strict;
use warnings;
use utf8;

use NG::Sys::Datetime;

sub add_fame {
	my $self = shift;
	my $value = shift;
	$self->fame($self->fame + $value);
}
sub store_fame {
	my $self = shift;
	my $date = unixtime2ydm(prev_day());
	if($self->lfame->insert({
			date => $date,
			value => $self->fame,
	})){
		$self->fame(0);
	}
}
sub summary_fame {
	my $self = shift;
	my $day = $self->{parent}{app}->constant->summary_fame;
	my @list = sort {$b->{date} cmp $a->{date}} @{$self->lfame->get_list};
	my @remove;
	if(@list > $day){
		@remove = splice @list,$day;
	}
	my $summ = 0;
	for(@list){
		$summ += $_->{value};
	}
	for(@remove){
		$self->lfame->extract($_->{date});
	}
	return $summ;
}
1;
